<template>
  <div>
    <span>全选:</span>
    <input type="checkbox" v-model="isAll" />
    <button>反选</button>
    <ul>
      <!-- 1.利用v-for遍历arr -->
      <li v-for="(item, index) in arr" :key="index">
        <!-- 2.多选框v-model绑定一个非数组 关联的是checked -->
        <input type="checkbox" v-model="item.c"/>
        <span>{{item.name}}</span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [
        {
          name: "小啊",
          c: false,
        },
        {
          name: "小布 ",
          c: false,
        },
        {
          name: "小哈哈 ",
          c: false,
        },
        {
          name: "小你",
          c: false,
        },
      ],
    };
  },
  computed: {
    isAll () {
      // 3.统计小选框状态 -> 全选
      // every口诀: 查找数组里"不符合"条件, 直接返回false
      // every:一假即假, some:一真即真 
      return this.arr.every(obj => obj.c === true)
    }
  }
};
</script>